<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/mb/jsp/common.jsp" %>

<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>活跃礼品</title>
     <!--pc版更改样式  -->
    <style>
    	.kmImg {
		    width: 195px;
		    height:132px;
		}
    </style>
</head>
<body ontouchstart="">
<div class="w100 db jz" style="padding-bottom: 0;padding-top: 46px;">

    <div id="inner-container" class="w100">

        <div id="resText"></div><!--resText-->
        <div id="loading" class="w100">
            <img src="mb/images/loading.gif" alt="正在加载" class="db jz hauto" style="width: 15px;">
            <div class="w100 tc f10 c9">正在加载</div>
        </div>
        
        <div id="contentId"></div>
        

</div>

 <script>


    //加载新数据
    function getData() {
        $.ajax({
            url: "PlugServlet",
            data: JSON.stringify({m: 1660}),
            type: 'post',
            dataType: 'json',
            contentType: "application/json;charset=utf-8",
            beforeSend: function () {
                showProgressDg();
            },
            success: function (data) {
            	console.log(data.list);
               if (data.state == 1) {
                  showData(data.list);
                } else {
                    // 其他错误弹出提示
                    layer.alert(data.info);
                }
            },
            error: function (data) {
                layer.alert(data.info);
            },
            complete: function () {
                closeProgressDg();
            }
        });
    }
    
    
     function showData(list)
    {
    	console.log(list);
    	var htmlStr="";
    	$.each(list, function(index, obj) 
    	{
    		var tmpimg=obj.prestigeimage.split(";")[0];
    		var projectid = obj.prestigeid;
			var btnBlock = "";
    		if(obj.prestigeintro == ""||obj.prestigeintro == undefined||obj.prestigeintro == null){
    		   obj.prestigeintro = "暂无";
    		};
			if(obj.isget == 0){
				btnBlock='<button class="w100 tc cf f15 modifyBtn btnBlue" onclick="getSth('+ projectid +')">领取</button>';
			}
			else if(obj.isget == 1){
			    btnBlock = '<button class="w100 tc cf f15 modifyBtn btnYlQ" disabled="disabled">已领取</button>'; 
			}
			
			
			var num = obj.limitenum - obj.buynum;
    		
    		if(num == 0){
    		   num = "0(无库存)";
    		   btnBlock = btnBlock = '<button class="w100 tc c6 f15 modifyBtn btnYlQ" disabled="disabled">不可领取</button>';
    		}
    		else if(num < 0){
    		  num = "error";
    		  btnBlock = btnBlock = '<button class="w100 tc c6 f15 modifyBtn btnYlQ" disabled="disabled">不可领取</button>';
    		}
    		
    		
    		//新增的iscanback属性
    		var iscanback = obj.iscanback;
    		var canbackLable = "";
    		if(iscanback == 0){
    		   canbackLable = '<p class="c9 f12 lh18">市场价:<span class="lineThroughSpan">'+obj.oldprice+'</span>&nbsp;&nbsp;(不支持回购)</p>';
    		}
    		else if(iscanback == 1){
    		  canbackLable = '<p class="c9 f12 lh18">市场价:<span class="lineThroughSpan">'+obj.oldprice+'</span>&nbsp;&nbsp;<span class="cred">回购价：'+obj.callbackprice+'</span></p>';
    		}
    		
    		
    		
    		var FloatAtrr ="";
			var outerDiv="";
			var outerDivEnd = "";
			if(index%2 == 0){
				FloatAtrr="fl";
				outerDiv='<div class="of pdt10 clearfix" style="padding:2px 5px;">';
			}else{
				FloatAtrr="fr";
				outerDivEnd = '</div>';
			}	
    		
			
    		htmlStr +=
    			outerDiv+
	    		   	'<section class="proSection pr w100 bcf '+FloatAtrr+'" style="width:49%;">'+
					   '<a href="mb/jsp/shengWangShangChengDetail.jsp?prestigeid=' + projectid + '" class="w100 db">'+
				            '<article class="of clearfix jz">'+
				                '<div class="fl" style="margin-left:2%;">'+
				                  '<img src="'+getBaseImgUrl(tmpimg)+'" class="kmImg mgt15">'+
				                '</div>'+
				                '<div class="fr dib lh2" style="margin:6px 2% auto;width:49%;">'+
				                    '<h5 class="c3 f13 mgt10 lh15">'+obj.prestigename+'</h5>'+
				                    '<p class="c9 f12">活跃值：'+obj.requirevalue+'&nbsp;&nbsp;剩余:'+num+'</p>'+
				                    canbackLable+
				                    '<p class="c9 f12 lh18" style="margin-top: 3px;">简介：'+obj.prestigeintro+'</p>'+
				                '</div>'+
				            '</article>'+
				        '</a>'+
				        '<div style="width:96%;border-top:1px solid #ececec;padding:7px 0;" class="jz mgt10">'+
				           btnBlock +
				        '</div>'+
					'</section>'+
					outerDivEnd; 
    		
    	});
    	
    	  $("#contentId").html(htmlStr);
    }
    
    
   // 领取
	function getSth(prestigeid) {
        $.ajax({
            url: "PlugServlet",
            data: JSON.stringify({m: 1662,prestigeid:prestigeid}),
            type: 'post',
            dataType: 'json',
            contentType: "application/json;charset=utf-8",
            beforeSend: function () {

            },
            success: function (data) {
 				console.log(data);
               if (data.state == 1) {
                  // 成功弹出提示
                  layer.alert(data.info);
                  window.location.reload();
                } else {
                    // 其他错误弹出提示
                   layer.alert(data.info);
                }
            },
            error: function (data) {
                layer.alert(data.info);
            },
            complete: function () {
                closeProgressDg();
            }
        });
    } 
    
    
    
    $(document).ready(function(){
	
		getData();
	  
	});
</script>


</body>
</html>
